<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>table模块快速使用</title>
    <link rel="stylesheet" href="lay/css/layui.css" media="all">
</head>
<body>
<script type="text/html" id="action">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<table id="demo" lay-filter="test"></table>

<script src="../layui/layui.js"></script>
<script src="../layui/lay/modules/table.js"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        var order_no;
        //第一个实例
        table.render({
            elem: '#demo'
            ,height: 312
            ,url: '../seckill?method=getSeckillList' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID', width:80},
                {field: 'goods_id', title: '商品编号', width:80},
                {field: 'goods_name',title:'商品名',width:80},
                {field: 'start', title: '开始时间', width:80},
                {field: 'end', title: '结束时间', width:80},
                {field: 'stotal', title: '活动数量', width:80},
                {field: 'num', title: '单件数量', width:80},
                {field: 'price', title: '秒杀价格', width:80},
                {field: 'state', title: '状态', width:80},
                {fixed:"right",title:'操作',toolbar:'#action',width:180}
            ]]
        });
        table.on('tool(test)',function(obj) {
            console.log(obj);
            console.log(obj.data)
            var data = obj.data;
            order_no = data.order_no;
            switch (obj.event) {
                case  'del':
                    layer.confirm("确定删除吗?",function (index) {
                        $.ajax({
                            url:"/seckill",
                            type:"post",
                            dataType:"json",
                            data:{"seckill_id":data.id,"method":"delete"},
                            success:function (msg) {
                                layer.close(index);
                                if(msg=="SUCCESS"){
                                    obj.del();
                                    layer.msg("删除成功！");
                                }else {
                                    layer.msg("删除失败");
                                }
                            }
                        })
                    })
                    break;
            }
        });

    });
</script>
</body>
</html>